/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import request from '@/utils/request';
import { isArray } from 'lodash';
import type { SearchParams } from '@/pages/CustomerServiceTools/types/PDDComplaintOrder';

export async function getPddComplainList(params: SearchParams, cb: Function): Promise<any> {
  return request('/PddTicket/getList', {
    method: 'POST',
    data: params,
  }).then(({ data }) => {
    const { list, count, page } = data || {};
    if (isArray(list) && list.length > 0) {
      cb(list);
      return {
        total: count,
        success: true,
        data: list,
        current: page,
      };
    }
    return {};
  });
}

export async function getPddComplainDetail(params: { id: string }): Promise<any> {
  return request('/PddTicket/getComplaintInfo', {
    method: 'POST',
    data: params,
  });
}

export async function passRecordToPDD(params: { record_id: string }): Promise<any> {
  return request('/PddTicket/passRecord', {
    method: 'POST',
    data: params,
  });
}

export async function getComplaintTypeInfo(params: { id: string }): Promise<any> {
  return request('/PddTicket/getComplaintTypeInfo', {
    method: 'POST',
    data: params,
  });
}

export async function pddComplaintSubmit(params: { id: string }): Promise<any> {
  return request('/PddTicket/ticketSave', {
    method: 'POST',
    data: params,
  });
}
